package Concurrency2.Chapter03_CAS_Atomic;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * Instruction：
 * Author：@author MaLi
 */
public class Utils4Unsafe {
    public static Unsafe getUnsafe() {
        Unsafe unsafe = null;
        try {
            Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
            theUnsafe.setAccessible(true);
            unsafe = (Unsafe) theUnsafe.get(null);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return unsafe;
    }
}
